﻿@using Subfaculty.WebApplication.ViewModels
@model IEnumerable<Subfaculty.WebApplication.ViewModels.StudyAreaViewModel>

	@{
		ViewBag.Title = "Содержимое";
		Layout = "~/Views/Shared/_LayoutAllocation.cshtml";
	}

@*	<fieldset class="main_fieldset">
			<legend class="main_legend">@ViewBag.Message</legend>*@
			
			@{
				Html.Telerik().Grid(Model)
					.Name("GridStudyArea")
					.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new {style = "margin-left:0"}))
					.DataKeys(keys => keys.Add(c => c.Id))
					.Columns(columns =>
				         		{
									columns.Bound(o => o.Code);
									columns.Bound(o => o.Name);
									columns.Command(commands =>
								                		{
															commands.Edit().ButtonType(GridButtonType.BareImage);
															commands.Delete().ButtonType(GridButtonType.BareImage);
															commands.Custom("viewDetails")
																.Text("Customer Details")
															.DataRouteValues(route => route.Add(o => o.Id).RouteKey("studyAreaId"))
															.Ajax(true)
															.Action("_ViewDetails", "StudyArea");
														}).Width(180).Title("Commands");
								}
					)
					.ClientEvents(events => events.OnComplete("onComplete"))
					.DataBinding(dataBinding =>
				             		{
										dataBinding.Server().Select("Index", "StudyArea", new { ajax = true });
										dataBinding.Ajax().Select("_Index", "StudyArea").Enabled(true);
										dataBinding.Ajax()
											.Select("SelectAjaxEditing", "StudyArea")
											.Insert("InsertAjaxEditing", "StudyArea")
											.Update("SaveAjaxEditing", "StudyArea")
											.Delete("DeleteAjaxEditing", "StudyArea");
									})
					.Editable(editing => editing.Mode(GridEditMode.PopUp))
					.Scrollable(scrolling => scrolling.Enabled(true))
					.Scrollable(scrolling => scrolling.Height("600px"))
					.Sortable(sorting => sorting.Enabled(true))
					.Pageable(paging => paging.Enabled(true))
					.Filterable(filtering => filtering.Enabled(true))
					.Selectable(s => s.Enabled(true))
					.Groupable(grouping => grouping.Enabled(true))
					.Footer(true)
					.Render();
			}
@(Html.Telerik().Window()
    .Name("Details")
    .Visible(false)
		.Title("Учебное направление (детали)")
    .Modal(true)
    .Width(400)
    .Height(500)
    .Content(@<text>
                <div id="studyArea-details">
				<fieldset>
				<legend>Учебное направвление</legend>
					<table>
						<tr>
							<td><h4>Наименование: </h4></td>
							<td>
								<div id="studyArea_name"></div>
							</td>
						</tr>
						<tr>
							<td><h4>Код: </h4></td>
							<td>
								<div id="studyArea_code"></div>
							</td>
						</tr>
						<tr>
							<td><h4>Профиль: </h4></td>
							<td>
								<div id="studyArea_profile"></div>
							</td>
						</tr>
						<tr>
							<td><h4>Квалификация: </h4></td>
							<td>
								<div id="studyArea_qual"></div>
							</td>
						</tr>
						<tr>
							<td><h4>Продолжительность (семестров): </h4></td>
							<td>
								<div id="studyArea_duration"></div>
							</td>
						</tr>
					</table>
					</fieldset>
                </div>
        </text>)
.Resizable()
.Draggable(true)
)

<script type="text/javascript">
function onComplete(e) {
   if (e.name == "viewDetails") {
        var detailWindow = $("#Details").data("tWindow");
        var studyArea = e.response.studyArea;
        $("#studyArea-details").
	        find("#studyArea_name").
	        text(studyArea.Name).
	        end()
        .find("#studyArea_code").
	        text(studyArea.Code).
	        end()
        .find("#studyArea_profile").
	        text(studyArea.Profile).
	        end()
        .find("#studyArea_qual").
	        text(studyArea.Qualification).
	        end()
        .find("#studyArea_duration").
	        text(studyArea.Duration).
	        end();
        detailWindow.center().open();
   } 
}
</script>
